package com.strato.orm.mybatis.v1_0_0.factory;

import com.strato.annotation.base.v1_0_0.registry.AnnotationRegistry;
import com.strato.annotation.base.v1_0_0.registry.BundleDescriptor;
import com.strato.base.aop.v1_0_0.AopFactory;
import com.strato.base.env.v1_0_0.GlobalEnvironment;
import com.strato.orm.mybatis.v1_0_0.annotation.handler.MybatisMapperInvocationInterceptor;

public class MapperFactory {

	public static <T> T getMapper(Class<T> mapperClass,String dataSourceName){
		BundleDescriptor bundleDesc = AnnotationRegistry.getInstance().findByClassName(mapperClass.getName());
		String bundleName=bundleDesc.getName();
		dataSourceName=GlobalEnvironment.getInstance().resolveString(dataSourceName);
		MybatisMapperInvocationInterceptor interceptor = new MybatisMapperInvocationInterceptor(bundleName,mapperClass.getName(),dataSourceName);
		@SuppressWarnings("unchecked")
		T proxy= (T) AopFactory.createProxy(mapperClass, interceptor);
		return proxy;
	}
	
}
